﻿Partial Public Class PhotosPage

    Public Sub New()
        InitializeComponent()
        MyInitialize()
    End Sub

    Private Sub MyInitialize()
        VirtualEarthMap.Icon = My.Settings.Pushpin
        minorMap.Connection = g_connection
        minorMap.AlbumManager = g_album_mgr
        minorMap.AutoResize = My.Settings.AutoResizeMap
        majorMap.Connection = g_connection
        majorMap.AlbumManager = g_album_mgr
        majorMap.AutoResize = My.Settings.AutoResizeMap
        AlbumSelectorControl1.MapControl = majorMap
        AddHandler g_currentphoto.Changed, AddressOf OnPhotoChanged
    End Sub

    Private Sub OnPhotoChanged()
        If g_currentphoto Is Nothing Then Return
        Dim row As DataRow = g_currentphoto.Row
        If row Is Nothing Then Return
        Dim rowguid As Guid = CType(row.Item("RowGuid"), Guid)
        If rowguid = Guid.Empty Then Return
        Trace.WriteLine("displaying image for row: " & rowguid.ToString())
        minorImage.Source = SpatialAlbum.Core.ImageUtils.LoadImageFromFilestream( _
                                    rowguid, My.Settings.TABLE_Photo, Schema.ImageFilestreamColumn, g_connection)
        Dim loc As SqlGeography = DirectCast(row.Item("Location"), SqlGeography)
        If Not loc.IsNull() Then
            minorMap.PanTo(loc.Lat, loc.Long)
        End If
    End Sub

    Private Sub VirtualEarthMapControl_PhotoClicked(ByVal VE_shapeid As String, ByVal row As System.Data.DataRow) Handles minorMap.PhotoClicked, majorMap.PhotoClicked
        g_currentphoto.Row = row
        'MessageBox.Show("click: " & VE_shapeid)
    End Sub

    Private Sub VirtualEarthMapControl_PhotoDoubleClicked(ByVal VE_shapeid As String, ByVal row As System.Data.DataRow) Handles minorMap.PhotoDoubleClicked, majorMap.PhotoDoubleClicked
        'MessageBox.Show("doubleclick: " & VE_shapeid)
        ImageViewerForm.ShowFullImage(g_currentphoto.Row)
    End Sub

    Private Sub minorImage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles minorImage.MouseDown
        If e.ClickCount <> 2 Then Return
        ImageViewerForm.ShowFullImage(g_currentphoto.Row)
        e.Handled = True
    End Sub
End Class
